Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
19 lines (16 loc) · 676 Bytes

3.4.3 - Coroutine/Http/Client->post.md

File metadata and controls

19 lines (16 loc) · 676 Bytes

Coroutine\Http\Client->post

发起POST请求,函数原型:

function Swoole\Coroutine\Http\Client->post(string $path, mixed $data);
  • $path 设置URL路径,如/index.html,注意这里不能传入http://domain
  • $data 请求的包体数据,如果$data为数组底层自动会打包为x-www-form-urlencoded格式的POST内容,并设置Content-Typeapplication/x-www-form-urlencoded
  • 使用post会忽略setMethod设置的请求方法,强制使用POST

使用实例

$cli = new Swoole\Coroutine\Http\Client('127.0.0.1', 80); 
$cli->post('/post.php', array("a" => '1234', 'b' => '456'));
echo $cli->body;
$cli->close();